package com.atguigu.ware.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.atguigu.common.to.es.SkuHasStockVo;
import org.springframework.web.bind.annotation.*;

import com.atguigu.ware.entity.WareSkuEntity;
import com.atguigu.ware.service.WareSkuService;
import com.atguigu.common.utils.PageUtils;
import com.atguigu.common.utils.R;

import javax.annotation.Resource;


/**
 * 商品库存
 *
 * @author polarisink
 * @email polarisink@163.com
 * @date 2020-12-18 15:40:40
 */
@RestController
@RequestMapping("ware/waresku")
public class WareSkuController {
  @Resource
  private WareSkuService wareSkuService;


  /**
   * 是否有库存
   *
   * @param skuIds
   * @return
   */
  @PostMapping("/hasstock")
  public R<List<SkuHasStockVo>> getSkuHasStock(@RequestBody List<Long> skuIds) {
    List<SkuHasStockVo> vos = wareSkuService.getSkusHasStock(skuIds);
    R<List<SkuHasStockVo>> ok = R.ok();
    ok.setData(vos);
    return ok;
//        return R.ok().put("data",vos);
  }

  /**
   * 列表
   */
  @RequestMapping("/list")
  public R list(@RequestParam Map<String, Object> params) {
    PageUtils page = wareSkuService.queryPage(params);

    return R.ok().put("page", page);
  }


  /**
   * 信息
   */
  @RequestMapping("/info/{id}")
  public R info(@PathVariable("id") Long id) {
    WareSkuEntity wareSku = wareSkuService.getById(id);

    return R.ok().put("wareSku", wareSku);
  }

  /**
   * 保存
   */
  @RequestMapping("/save")
  public R save(@RequestBody WareSkuEntity wareSku) {
    wareSkuService.save(wareSku);

    return R.ok();
  }

  /**
   * 修改
   */
  @RequestMapping("/update")
  public R update(@RequestBody WareSkuEntity wareSku) {
    wareSkuService.updateById(wareSku);

    return R.ok();
  }

  /**
   * 删除
   */
  @RequestMapping("/delete")
  public R delete(@RequestBody Long[] ids) {
    wareSkuService.removeByIds(Arrays.asList(ids));

    return R.ok();
  }

}
